#pragma once 

class Obj;

#include "ControlGroup.h"

class PlayerObj;

// The game has one ObjContainer which owns all game objects
// class is used for rendering and picking
// possibly other 'global' simulations that use all game objects
// Independent of players, player army only point to objects held by the container 

class ObjContainer 
{
public:
	static ObjContainer* getInstance();
		
	Obj* colorPick(FBO_RB pickingFBO, const glm::dvec2& mousePos);
	void addObj(Obj* obj);
	void renderForPicking(FBO_RB pickingFBO, const glm::mat4& viewMatrix);
	void draw(const glm::mat4& viewMatrix, bool picking = false);
	void update(float dt);
	bool walkable(const glm::vec2 & pos, float radius);
	PlayerObj* getClosestPlayerObj(Player* ignore, glm::vec3 & pos, float radius);
	
private:
	Obj* getObjFromColor(const glm::vec4& color);

	std::vector<Obj*> objList;
	std::vector<Obj*> addsScheduled;
	
	ObjContainer();
	static ObjContainer* instance;
};

class Army
{
public:
    Army();
    ~Army();

    void addObj(PlayerObj* obj);
    PlayerObj* getObj(const glm::vec4& pixel);
    ControlGroup& getCG() { return activeCG; }
	void move(glm::vec2 & dest);
	void boxSelect(const glm::dvec4& box, const glm::mat4& viewMatrix, bool shiftHeld);
	void colorSelect(const glm::vec4& pixel, bool shiftHeld);
	PlayerObj* getClosesTarget(const glm::vec3 & pos, float radius);

private:
    std::vector<PlayerObj*> objList;
    ControlGroup activeCG;
};